package com.team.six.bluecatshop.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebFilter(urlPatterns = {"/adminProduct/*","/adminSku/*","/adminProductType/*","/adminIndent/*","/adminActivity/*"}, filterName = "AdminFilterConfig")
public class AdminFilterConfig implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse resp = (HttpServletResponse) servletResponse;
        HttpSession session = req.getSession();
        if(session.getAttribute("adminName")==null){

            resp.sendRedirect("/admin/adminLogin");
        }else {
            filterChain.doFilter(servletRequest, servletResponse);
        }
    }
}
